home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-11-20 | 9.3 KB | 291 lines | [TEXT/CWIE] |
- // SVAppleEvents.c
- //
- // 7Edit 3.1d1. Original version by Jon Lansdell and Nigel Humphreys.
- // 3.1 updates by Greg Sutton.
- // ©Apple Computer Inc 1995, all rights reserved.
-
- #include "SVAppleEvents.h"
-
- #include <Resources.h>
-
- #include "SVEditGlobals.h"
- #include "SVEditUtils.h"
- #include "SVEditAEUtils.h"
- #include "SVEditWindow.h"
- #include "SVEditFile.h"
-
- #include "SVAERecording.h"
- #include "SVEditGXPrinting.h"
-
- #include "SVAECompare.h"
- #include "SVAECountElements.h"
- #include "SVAEAccessors.h"
- #include "SVAECoercions.h"
- #include "SVAEObjectsExist.h"
- #include "SVAECreate.h"
- #include "SVAEClone.h"
- #include "SVAEMove.h"
- #include "SVAEDelete.h"
- #include "SVAECopy.h"
- #include "SVAECut.h"
- #include "SVAEPaste.h"
- #include "SVAESelect.h"
- #include "SVAEClose.h"
- #include "SVAESave.h"
- #include "SVAERevert.h"
- #include "SVAEGetData.h"
- #include "SVAESetData.h"
- #include "SVAEGetDataSize.h"
-
- short gRefNum;
-
- #pragma segment Main
-
- /*-----------------------------------------------------------------------*/
- /**---------- APPLE EVENT HANDLING ---------------**/
- /*-----------------------------------------------------------------------*/
-
-
- // -----------------------------------------------------------------------
- // Name: DoAppleEvent
- // Purpose: Process and despatch the AppleEvent
- // -----------------------------------------------------------------------
-
- void DoAppleEvent(EventRecord theEvent)
- {
- OSErr err;
-
- // should check for your own event message types here - if you have any
-
- err = AEProcessAppleEvent(&theEvent);
- }
-
- // -----------------------------------------------------------------------
- // Name: DoOpenApp
- // Purpose: Called on startup, creates a new document.
- // -----------------------------------------------------------------------
-
- pascal OSErr DoOpenApp(const AppleEvent *message,const AppleEvent *reply,long refcon)
- {
- #pragma unused (reply,refcon, message)
-
- DPtr ourDoc;
-
- /*just create a new document*/
- ourDoc = NewDocument(false, (WindowPtr)-1L);
-
- if (ourDoc)
- {
- ShowWindow(ourDoc->theWindow);
- return(noErr);
- }
- else
- return(-108);
- }
-
- // -----------------------------------------------------------------------
- // Name: DoOpenDocument
- // Purpose: Open all the documents passed in the Open AppleEvent.
- // -----------------------------------------------------------------------
-
- pascal OSErr DoOpenDocument(const AppleEvent *message, const AppleEvent *reply, long refcon)
- {
- #pragma unused (reply, refcon)
-
- long index;
- long itemsInList;
- AEKeyword keywd;
- OSErr err;
- OSErr ignoreErr;
- AEDescList docList;
- long actSize;
- DescType typeCode;
- FSSpec theFSSpec;
-
- /*open the specified documents*/
-
- docList.dataHandle = nil;
-
- err = AEGetParamDesc(message, keyDirectObject, typeAEList, &docList);
-
- if (err==noErr)
- err = AECountItems( &docList, &itemsInList) ;
- else
- itemsInList = 0;
-
- for (index = 1; index <= itemsInList; index++)
- if (err==noErr)
- {
- err = AEGetNthPtr( &docList, index, typeFSS, &keywd, &typeCode,
- (Ptr)&theFSSpec, sizeof(theFSSpec), &actSize ) ;
- if (err==noErr)
- err = OpenOld(theFSSpec);
- }
-
- if (docList.dataHandle)
- ignoreErr = AEDisposeDesc(&docList);
-
- return(err);
- }
-
- // -----------------------------------------------------------------------
- // Name: MyQuit
- // Purpose: Quit event received- exit the program.
- // -----------------------------------------------------------------------
-
- pascal OSErr MyQuit(const AppleEvent *message,const AppleEvent *reply,long refcon)
- {
- #pragma unused (reply,refcon)
-
- DescType saveOpt;
- OSErr tempErr;
- OSErr myErr;
- DescType returnedType;
- long actSize;
-
- saveOpt = kAEAsk; /* the default */
- tempErr = AEGetParamPtr(message,
- keyAESaveOptions,
- typeEnumerated,
- &returnedType,
- (Ptr)&saveOpt,
- sizeof(saveOpt),
- &actSize);
-
- if (saveOpt != kAENo)
- myErr = AEInteractWithUser(kAEDefaultTimeout, nil, nil);
-
- if (myErr == noErr)
- DoQuit(saveOpt);
-
- return(myErr);
- }
-
-
- // -----------------------------------------------------------------------
- // Name: DoPrintDocuments
- // Purpose: Print a list of documents (or windows).
- // -----------------------------------------------------------------------
-
- pascal OSErr DoPrintDocuments(const AppleEvent *message, AppleEvent *reply, long refcon)
- {
- #pragma unused (reply, refcon)
- long index;
- long itemsInList;
- AEKeyword keywd;
- OSErr err;
- AEDescList docList;
- Size actSize;
- DescType typeCode;
- FSSpec theFSSpec;
- WindowToken theWindowToken;
- OSErr forgetErr;
- Boolean talkToUser;
-
- err = AEGetParamDesc(message,
- keyDirectObject,
- typeAEList,
- &docList);
-
- err = AECountItems(&docList, &itemsInList);
-
- for (index = 1; index<=itemsInList; index++)
- if (err == noErr)
- {
- forgetErr = AEGetNthPtr( &docList, index, typeFSS, &keywd,
- &typeCode, (Ptr)&theFSSpec, sizeof(theFSSpec), &actSize);
-
- talkToUser = false; // (AEInteractWithUser(kAEDefaultTimeout, nil, nil) == noErr);
-
- if (forgetErr == noErr)
- {
- if (err == noErr)
- err = IssueAEOpenDoc(theFSSpec);
-
- if (err == noErr)
- IssuePrintWindow(FrontWindow(), talkToUser);
-
- if (err == noErr)
- IssueCloseCommand(FrontWindow());
- }
- else
- { /* wasn't a file - was it a window ? */
- err = AEGetNthPtr(&docList,
- index,
- typeMyWndw,
- &keywd,
- &typeCode,
- (Ptr)&theWindowToken,
- sizeof(WindowToken),
- &actSize);
-
-
- if (err == noErr)
- if (gGXIsPresent)
- err = GXPrintDocument(DPtrFromWindowPtr(theWindowToken.tokenWindow), talkToUser);
- else
- PrintWindow(DPtrFromWindowPtr(theWindowToken.tokenWindow), talkToUser);
- }
- }
-
- if (docList.dataHandle)
- forgetErr = AEDisposeDesc(&docList);
-
- return(err);
- } /* DoPrintDocuments */
-
-
- // -----------------------------------------------------------------------
- // Name: InitAppleEvents
- // Purpose: Initialise the AppleEvent despatch table
- // -----------------------------------------------------------------------
-
- void InitAppleEvents(void)
- {
- OSErr aevtErr;
-
- gRefNum = CurResFile(); // Needed for getting application property
-
- // set up the dispatch table for the four standard AppleEvents
-
- aevtErr = AEInstallEventHandler( kCoreEventClass, kAEOpenApplication, NewAEEventHandlerProc(DoOpenApp), noRefCon, false) ;
- aevtErr = AEInstallEventHandler( kCoreEventClass, kAEOpenDocuments, NewAEEventHandlerProc(DoOpenDocument), noRefCon, false) ;
- aevtErr = AEInstallEventHandler( kCoreEventClass, kAEPrintDocuments, NewAEEventHandlerProc(DoPrintDocuments), noRefCon, false) ;
- aevtErr = AEInstallEventHandler( kCoreEventClass, kAEQuitApplication, NewAEEventHandlerProc(MyQuit), noRefCon, false) ;
-
- // set up the dispatch table for the core AppleEvents
-
- aevtErr = AEInstallEventHandler( kAECoreSuite, kAESetData, NewAEEventHandlerProc(DoSetData), noRefCon, false);
- aevtErr = AEInstallEventHandler( kAECoreSuite, kAEGetData, NewAEEventHandlerProc(DoGetData), noRefCon, false);
- aevtErr = AEInstallEventHandler( kAECoreSuite, kAEGetDataSize, NewAEEventHandlerProc(DoGetDataSize), noRefCon, false);
- aevtErr = AEInstallEventHandler( kAECoreSuite, kAECountElements, NewAEEventHandlerProc(DoCountElements), noRefCon, false);
- aevtErr = AEInstallEventHandler( kAECoreSuite, kAEDoObjectsExist, NewAEEventHandlerProc(DoObjectsExist), noRefCon, false);
- aevtErr = AEInstallEventHandler( kAECoreSuite, kAECreateElement, NewAEEventHandlerProc(DoNewElement), noRefCon, false);
- aevtErr = AEInstallEventHandler( kAECoreSuite, kAEClone, NewAEEventHandlerProc(DoClone), noRefCon, false);
- aevtErr = AEInstallEventHandler( kAECoreSuite, kAEDelete, NewAEEventHandlerProc(DoDelete),noRefCon, false);
- aevtErr = AEInstallEventHandler( kAECoreSuite, kAEMove, NewAEEventHandlerProc(DoMove), noRefCon, false);
- aevtErr = AEInstallEventHandler( kAECoreSuite, kAEClose, NewAEEventHandlerProc(DoCloseWindow),noRefCon, false);
- aevtErr = AEInstallEventHandler( kAECoreSuite, kAESave, NewAEEventHandlerProc(DoSaveWindow),noRefCon, false);
-
- // set up the dispatch table for the miscellaneous AppleEvents
-
- aevtErr = AEInstallEventHandler( kAEMiscStandards, kAECut, NewAEEventHandlerProc(DoCut), noRefCon, false);
- aevtErr = AEInstallEventHandler( kAEMiscStandards, kAECopy, NewAEEventHandlerProc(DoCopy), noRefCon, false);
- aevtErr = AEInstallEventHandler( kAEMiscStandards, kAEPaste, NewAEEventHandlerProc(DoPaste), noRefCon, false);
- aevtErr = AEInstallEventHandler( kAEMiscStandards, kAERevert, NewAEEventHandlerProc(DoRevert),noRefCon, false);
- aevtErr = AEInstallEventHandler( kAEMiscStandards, kAESelect, NewAEEventHandlerProc(DoSelect),noRefCon, false);
-
- // Install recording handlers
- aevtErr = InstallRecordingHandlers();
-
- // Install callbacks for count and compare procedures
- aevtErr = InstallObjectCallbacks();
-
- // Now install our object accessors
- aevtErr = InstallAccessors();
-
- // Now the coercion handlers
- aevtErr = InstallCoercions();
-
- } // InitAppleEvents
-